﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lg.Core
{
    public static class Random
    {
        public static object _lock = new object();
        public static int count = 0;
        /// <summary>
        /// 获取一个以时间+递增数的数字串，常用于不重复的数字命名条件
        /// </summary>
        /// <param name="l">时期时间字串后面的递增数的位数</param>
        /// <returns>数字字符串</returns>
        public static string NewRandom(int l)
        {
            int maxNum = (int)Math.Pow(10, l - 1);
            string sn = "";

            if (count >= maxNum)
            {
                count = 1;
            }
            lock (_lock)
            {
                sn = DateTime.Now.ToString("yyyyMMddHHmmssfff") + count.ToString(maxNum.ToString().Replace("1", "0"));
                count++;
            }
            return sn;
        }
    }
}
